﻿using HighThroughput.ShareData;
using Newtonsoft.Json;
using OSSUtility.BLL;
using OSSUtility.Models;
using Ozone.BLL;
using Ozone.DAL;
using Ozone.Device;
using Ozone.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using static Ozone.Models.KeyPoint;

namespace Ozone.Views.SystemCenter.AdvancedParameter
{
    /// <summary>
    /// UserControl1.xaml 的交互逻辑
    /// </summary>
    public partial class UpdateRobotPo : UserControl
    {
        public UpdateRobotPo()
        {
            InitializeComponent();
            initCombox();
            InitPoint();
            //TestAddRP();
            //TestDelete();
            //TestUpdate();
            //TestQuery();
        }
        public static PointXYZ DeepCopy(PointXYZ source)
        {
            if (source == null) return null;
            return new PointXYZ()
            {
                X = source.X,
                Y = source.Y,
                Z = source.Z,
                A = source.A,
                B = source.B,
                C = source.C,
            };
        }
        void InitPoint()
        {
            TextB_GetA.Text = SetRobotPointsBLL.GetPoint(SetRobotPointsBLL.PointName.GetA).PoValue;
            TextB_GetC.Text = SetRobotPointsBLL.GetPoint(SetRobotPointsBLL.PointName.GetC).PoValue;
            TextB_CToD.Text = SetRobotPointsBLL.GetPoint(SetRobotPointsBLL.PointName.CPutD).PoValue;

        }
        void initCombox()
        {
            List<int> lstComE = new List<int>();
            for (int i = 1; i < 21; i++)
            {
                lstComE.Add(i);
            }
            comboBox_ToE.ItemsSource = lstComE;
            comboBox_ToE.SelectedIndex = 0;
            comboBox_A2BPos.ItemsSource = lstComE;
            comboBox_A2BPos.SelectedIndex = 0;
            TextB_A2B.Text = SetRobotPointsBLL.GetPoint(SetRobotPointsBLL.PointName.APutB[0]).PoValue;
            TextB_GetE.Text = SetRobotPointsBLL.GetPoint(SetRobotPointsBLL.PointName.GetE[0]).PoValue;

        }
        #region sql test测试
        void TestAddRP()
        {
            List<robot_points> lstrobot_p = new List<robot_points>()
            {
                new robot_points()
                {
                    FID = "4",
                    PoName = "GetE",
                    PoValue = "1,2,3,4,5,6",
                    ToolName = "Tool2",
                    ToolValue ="2,2,2,2,2,2",
                    Remarks = "说明: E为同一区域内的点位，路径相差小，如20孔位试管架",
                    CreateTime = DateTime.Now,
                    ModifyTime = DateTime.Now,
                },
                new robot_points()
                {
                    FID = "5",
                    PoName = "APutB",
                    PoValue = "1,2,3,4,5,6",
                    ToolName = "Tool1",
                     ToolValue ="1,1,1,1,1,1",
                    Remarks = " A或B为同一区域内的点位",
                    CreateTime = DateTime.Now,
                    ModifyTime = DateTime.Now,
                },
                new robot_points()
                {
                    FID = "6",
                    PoName = "CPutD",
                    PoValue = "1,2,3,4,5,6",
                    ToolName = "Tool2",
                    ToolValue ="2,2,2,2,2,2",
                    Remarks = "说明: 不是所有点位都到达上方，如倒液直接到达倒液点位并做出倒液动作",
                    CreateTime = DateTime.Now,
                    ModifyTime = DateTime.Now,
                }
            };
            SetRobotPointsBLL.AddRP(lstrobot_p);
        }
        void TestDelete()
        {
            List<string> lstPoName = new List<string>();
            lstPoName.Add("GetA");
            lstPoName.Add("GetB");
            lstPoName.Add("GetC");
            SetRobotPointsBLL.DeleteRP(lstPoName);
        }
        void TestUpdate()
        {
            List<robot_points> lstrobot_p = new List<robot_points>()
            {
                new robot_points()
                {
                    FID = "1",
                    PoName = "GetA",
                    PoValue = "1,2,3,4,5,6",
                    ToolName = "Tool2",
                    ToolValue ="2,2,2,2,2,2",
                    Remarks = "取放离心管使用Tool工具坐标系，使用工具坐标系后 XYZABC角度会重新标定,方向不好寻找，需速度变慢执行!",
                    CreateTime = DateTime.Now,
                    ModifyTime = DateTime.Now,
                },
                new robot_points()
                {
                    FID = "2",
                    PoName = "GetB",
                    PoValue = "1,2,3,4,5,6",
                    ToolName = "Tool1",
                     ToolValue ="1,1,1,1,1,1",
                    Remarks = "说明: 取放离心管使用Tool工具坐标系，使用工具坐标系后 XYZABC角度会重新标定,方向不好寻找，需速度变慢执行!",
                    CreateTime = DateTime.Now,
                    ModifyTime = DateTime.Now,
                },
                new robot_points()
                {
                    FID = "3",
                    PoName = "GetC",
                    PoValue = "1,2,3,4,5,6",
                    ToolName = "Tool2",
                    ToolValue ="2,2,2,2,2,2",
                    Remarks = "说明: 取放离心管使用Tool工具坐标系，使用工具坐标系后 XYZABC角度会重新标定,方向不好寻找，需速度变慢执行!",
                    CreateTime = DateTime.Now,
                    ModifyTime = DateTime.Now,
                }
            };
            SetRobotPointsBLL.UpdateRP(lstrobot_p);
        }
        void TestQuery()
        {
            List<robot_points> lstrobot_p = new List<robot_points>();
            //lstrobot_p = SetRobotPointsBLL.QureyRP("GetA");
            lstrobot_p = SetRobotPointsBLL.QureyRP(DateTime.MinValue, DateTime.Now);
        }
        #endregion

        private void btnReset_click(object sender, RoutedEventArgs e)
        {

        }

        private void BtnJawControl_click(object sender, RoutedEventArgs e)
        {

        }

        private void BtnAdgust_click(object sender, RoutedEventArgs e)
        {

        }

        private void BtnGetCurrentPoint_click(object sender, RoutedEventArgs e)
        {

        }
        /// <summary>
        /// 保存点位
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;
            string sTag = button.Tag.ToString();
            switch (sTag)
            {
                case "A":
                    PointXYZ pointCurrent  = new PointXYZ(90,90,90,90,90,90);//Test,获取当前点位
                    SetRobotPointsBLL.SavePoint(SetRobotPointsBLL.PointName.GetA, pointCurrent, "Tool1","1,1,1,1,1,1");
                    break;
            }
        }
        /// <summary>
        /// 机械臂运动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnMove_click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;
            string sTag = button.Tag.ToString();
            switch (sTag)
            {
                
            }
        }

        private void combToEChanged(object sender, SelectionChangedEventArgs e)
        {
            int nSelect = (int)comboBox_ToE.SelectedValue;
            TextB_GetE.Text = SetRobotPointsBLL.GetPoint(SetRobotPointsBLL.PointName.GetE[nSelect - 1]).PoValue;

        }

        private void comba2bpOSSelectChanged(object sender, SelectionChangedEventArgs e)
        {
            int nSelect = (int)comboBox_A2BPos.SelectedValue;
            TextB_A2B.Text = SetRobotPointsBLL.GetPoint(SetRobotPointsBLL.PointName.APutB[nSelect-1]).PoValue;
        }
        /// <summary>
        /// 使用新点位执行动作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNewMove_click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;
            string sTag = button.Tag.ToString();
        }
    }
}
